package com.hzhr.iot.user.controller;

import com.hzhr.iot.core.annotation.ApiImplicitInternalParams;
import com.hzhr.iot.core.annotation.Author;
import com.hzhr.iot.core.dto.ResponseExceptionDto;
import com.hzhr.iot.core.exception.ServiceException;
import com.hzhr.iot.user.controller.base.BaseController;
import com.hzhr.iot.user.model.user.UserGetModel;
import com.hzhr.iot.user.model.user_password.User_PasswordGetModel;
import com.hzhr.iot.user.model.user_password.User_PasswordPutModel;
import com.hzhr.iot.user.service.UserService;
import com.hzhr.iot.user.service.User_PasswordService;
import io.swagger.annotations.*;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Map;

@Api(tags = "User_Password", description = "用户的密码")
@RestController
@RequestMapping(value = "")
public class User_PasswordController extends BaseController {
    @Autowired
    User_PasswordService user_passwordService;

    //region /users/passwords GET
    //region swagger响应码 : get
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功"),
    })
    //endregion
    //region swagger说明 : get
    @ApiOperation(value="查询用户的密码", notes="查询用户的密码  \n步骤 :  \n1. 查询用户的密码 : (√)  \n根据条件参数查询UserEntity对象user_1；  \n2. 返回信息 : (√)  \n根据user_1生成结果对象并返回;  \n",produces = "application/json")
    //endregion
    //region swagger参数 : get
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),

            @ApiImplicitParam(name = "show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "equal_id", value = "筛选条件 : where User_PasswordModel.id = #{equal_id}",required = true, dataType = "int", paramType = "query"),

    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),

            @ApiImplicitParam(name = "_show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_equal_id", value = "筛选条件 : where User_PasswordModel.id = #{equal_id}",required = true, dataType = "int", paramType = "query"),

    })
    //endregion
    //region 请求 : get
    @RequestMapping(value = "/users/passwords", method = RequestMethod.GET)
    //endregion
    @Author
    public ResponseEntity<User_PasswordGetModel> get(@RequestParam @ApiIgnore Map<String, Object> query) throws ServiceException {
        User_PasswordGetModel responseBody = user_passwordService.get(initHeader(), query);
        return new ResponseEntity<>(responseBody, HttpStatus.OK);
        //endregion
    }
    //endregion

    //region /users/{userId}/passwords PUT
    //region swagger响应码 : putByUserId
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功"),
            @ApiResponse(code = 403, message = "----异常代码 : 201  \n----异常类型 : 业务流程异常  \n----异常业务 : 查询用户  \n----异常说明 : 用户不存在  \n\n", response = ResponseExceptionDto.class),
    })
    //endregion
    //region swagger说明 : putByUserId
    @ApiOperation(value="根据用户编号修改用户的密码", notes="根据用户编号修改用户的密码  \n步骤 :  \n1. 查询用户 : (√)  \n根据以下筛选条件查询UserEntity对象user_1:  \n          (1) user_1.id == 路径参数userId  \n如果user_1不存在，抛出异常201；  \n2. 修改用户密码 : (√)  \n根据以下规则修改user_1：  \n          (1) user_1 = body.password；  \n3. 返回信息  \n查询修改后的user_1，并根据user_1、修改数量以及条件参数生成结果对象并返回；  \n",produces = "application/json")
    //endregion
    //region swagger参数 : putByUserId
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),

            @ApiImplicitParam(name = "userId", value = "用户编号",required = true, dataType = "int", paramType = "path"),

    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),
    })
    //endregion
    //region 请求 : putByUserId
    @RequestMapping(value = "/users/{userId}/passwords", method = RequestMethod.PUT)
    //endregion
    @Author
    public ResponseEntity<User_PasswordGetModel> putByUserId(@PathVariable("userId") Integer userId,
                                                             @RequestParam @ApiIgnore Map<String, Object> query,
                                                             @RequestBody User_PasswordPutModel body) throws ServiceException {
        User_PasswordGetModel responseBody = user_passwordService.putByUserId(initHeader(), userId, query, body);
        return new ResponseEntity<>(responseBody, HttpStatus.OK);
        //endregion
    }
    //endregion
}
















































































































































































































































































































































































